var WxParse = require('../../../wxParse/wxParse.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gameurl:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    WxParse.emojisInit('[]', "/wxParse/emojis/", {});
    this.loadToServer(options.goodsid);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // WxParse.wxParse('article', 'html', article, that, 5);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return app.getShareObj();
  },
  loadToServer: function (goodsid) {
    var url = app.globalData.webUrl + 'Goods/informactionmsg';

    var tdata = { goodsid: goodsid };

    app.loadDataFromServer(url, this.loadCallBack, tdata);
  },
  loadCallBack: function (res) {
    wx.hideToast();
    if (res.status != 'ok') {
      wx.showToast({
        title: '网络错误~',
        image: '../../imgs/tips.png'
      });
      return;
    }
    var article = res.result.ginfo.htmlmsg;
    article = article.replace(/&nbsp;/g,'');
    article = article.replace(/amp;/g, '');
    // console.log(article);
    var title = res.result.ginfo.gname;
    var datetime = res.result.ginfo.addtime;
    datetime = app.formatDateTime(datetime);
    
    this.setData({
      title: title,
      datetime: datetime,
      ginfo: res.result.ginfo,
      gameinfo:res.result.gameinfo
    });
    WxParse.wxParse('article', 'html', article, this, 5);
  },
  intoGame:function(){
    var gameid = this.data.gameinfo.gameid;
    console.log(app.globalData.userInfo);
    var storeid = app.globalData.storeid;
    var userid = wx.getStorageSync('uid');
    var gameurl = this.data.gameinfo.gameurl + '?gameid=' + gameid + '&storeid=' + storeid + '&userid=' + userid;
    
    wx.setStorageSync('curtourls', gameurl);
    wx.navigateTo({
      url: '../../htmlview/htmlview',
    });
  }

})